package com.zhkj.txg.module.home.adapter

import android.graphics.Paint
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.google.gson.Gson
import com.zhkj.lib.config.BASE_URL
import com.zhkj.lib.utils.SpanUtil
import com.zhkj.txg.R
import com.zhkj.txg.module.home.entity.PromotionInfo
import com.zhkj.txg.module.home.entity.RecommendInfo
import com.zhkj.txg.utils.ImageUtils

class HomeFlashSaleAdapter : BaseQuickAdapter<PromotionInfo, BaseViewHolder>(R.layout.item_home_flash_sale) {

    override fun convert(helper: BaseViewHolder, item: PromotionInfo) {
        val json = Gson()
        LogUtils.e("=====${json.toJson(item)}")
        val imageView = helper.setText(
            R.id.tvFlashSalePrice,
            if (item.activePrice.isNullOrEmpty()) SpanUtil.setMoneySymbol(item.price, true) else SpanUtil.setMoneySymbol(item.activePrice, true)
        ).setText(R.id.tvFlashSalePrice2, SpanUtil.setMoneySymbol(item.price, false))
            .getView<ImageView>(R.id.imageFlashSale)
        helper.getView<TextView>(R.id.tvFlashSalePrice2).paint.flags = Paint.STRIKE_THRU_TEXT_FLAG
        ImageUtils.loadImage(
            context, imageView,
            if (item.image.startsWith("http")) item.image else BASE_URL + item.image
        )
    }
}